<!--  button 按钮 - 属性面板 -->
<template>
  <div class="buttonAttr">
    <div class="content">
      <div class="title">
        {{ attributeset.lab }}
      </div>
      <div v-if="attributeset.data" class="list">
        <div class="lab">字段标题：<span>最多30个字</span></div>
        <div>
          <t-input
            v-model="attributeset.data.title"
            type="text"
            size="small"
            :maxlength="30"
            placeholder="请输入"
          />
        </div>
        <div class="lab">按钮名称<span>最多30个字</span></div>
        <div>
          <t-input
            v-model="attributeset.data.name"
            type="text"
            size="small"
            :maxlength="30"
            placeholder="请输入"
          />
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">表单宽度：</div>
          <div class="slider">
            <t-slider v-model="attributeset.data.width" size="small" />
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">表单列数</div>
          <div>
            <t-radio-group
              v-model="attributeset.data.defaultWidth"
              default-value="1"
              size="small"
              @change="widthChange"
            >
              <t-radio-button value="1">一列</t-radio-button>
              <t-radio-button value="2">两列</t-radio-button>
              <t-radio-button value="3">三列</t-radio-button>
              <t-radio-button value="4">四列</t-radio-button>
            </t-radio-group>
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">显示标题</div>
          <div><t-switch v-model="attributeset.data.isShowTitle" /></div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">隐藏组件</div>
          <div><t-switch v-model="attributeset.data.isShow" /></div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">按钮功能</div>
          <div>
            <t-select
              v-model="attributeset.data.type"
              size="small"
              style="margin-bottom: 8px"
            >
              <t-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </t-select>
            <t-input-adornment
              :prepend="attributeset.data.type === 'url' ? `http://` : `tel：`"
              size="small"
            >
              <t-input
                v-model="attributeset.data.value"
                :placeholder="
                  attributeset.data.type === 'url'
                    ? '请输入跳转url'
                    : '请输入手机号'
                "
                size="small"
                type="text"
              />
            </t-input-adornment>
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">排列方式</div>
          <div>
            <t-radio-group
              v-model="attributeset.data.align"
              default-value="flex-start"
              size="small"
            >
              <t-radio-button value="flex-start">左边</t-radio-button>
              <t-radio-button value="center">居中</t-radio-button>
              <t-radio-button value="flex-end">右边</t-radio-button>
            </t-radio-group>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { reactive, watch } from 'vue'

const props = defineProps({
  arrtData: Object
})

const options = [
  { label: '跳转链接', value: 'url' },
  { label: '电话拨号', value: 'phone' }
]

let attributeset = reactive({ ...props.arrtData })

// 处理列的调整宽度
const widthChange = (val) => {
  switch (val) {
    case '1':
      attributeset.data.width = 100
      break
    case '2':
      attributeset.data.width = 50
      break
    case '3':
      attributeset.data.width = 33.3
      break
    case '4':
      attributeset.data.width = 25
      break
  }
}

// 接收父级的方法
const emit: Function = defineEmits(['changeAttrHandle'])
// 同步调整attributeset
watch(
  () => props.arrtData,
  (val) => {
    attributeset = { ...val }
  },
  { deep: true }
)
// 监听整个表单的输入
watch(
  () => attributeset,
  (val) => {
    emit('changeAttrHandle', val)
  },
  { deep: true }
)
</script>
<style src="../../index.less" scoped></style>
